﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TicTacToe
{
    public class BoardManager
    {
        private static IGameAlgorithm gameAlgorithm = new MinimaxAlgorithm();

        public static IGameAlgorithm GameAlgorithm
        {
            set
            {
                gameAlgorithm = value;
            }
        }

        public static bool IsGameComplete(Board board)
        {
            if(board.Evaluate(BoardPlayer.Computer) ||
                board.Evaluate(BoardPlayer.Player) ||
                board.IsFull())
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public static BoardPlayer GetWinnder(Board board)
        {
            if(board.Evaluate(BoardPlayer.Computer))
            {
                return BoardPlayer.Computer;
            }
            else if(board.Evaluate(BoardPlayer.Player))
            {
                return BoardPlayer.Player;
            }
            else
            {
                return BoardPlayer.NoPlayer;
            }
        }

        public static void MakeMoveOnBoard(Board board, BoardPlayer player, int position)
        {
            board[position] = player;
        }

        public static int ComputeBestMove(Board board)
        {
            return gameAlgorithm.Solve(board);
        }

        public static int ComputeRandomMove()
        {
            return new Random().Next(8);
        }
    }
}